<template>
	<view>
		<scroll-view scroll-y 
		:style="{height:'calc(100vh - ' + height + 'rpx - env(safe-area-inset-bottom))'}">
			<slot name="title" :dataList="dataList" :otherParams="otherParams"></slot>
			<slot name="content" :dataList="dataList" :otherParams="otherParams"></slot>
			<uni-load-more :status="loadMoreStatus"></uni-load-more>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		name:"yw-list",
		props:{
			api: {
			  type:String,
			  required:true,
			  default:"",
			},
			height:{
				default:124,
				type:Number,
				required:true
			},
			otherParams:{
				default:{}
			}
		},
		data() {
			return {
				searchDate:{
				},
				loadMoreStatus:'noMore',
				dataList:[]
			};
		},
		mounted() {
		},
		methods:{
			scrolltolower() {
				this.findAllByPage()
			},
			shuaxin(params,testData) {
				//将参数添加到search
				if(uni.$common.isNotNull(params)){
					uni.$common.obj2obj(params,this.searchDate)
				}
				
				if(testData && testData.isTest == true){
					this.dataList = testData.dataList
					if(testData.filterEvent){
						this.dataList = this.dataList.filter(testData.filterEvent)
					}
				}
				this.findAllByPage()
			},
			findAllByPage(){
				if(uni.$common.isBlank(this.api)){
					return
				}
				
				let apiPage = uni.$api[this.api]
				if(uni.$common.isBlank(apiPage)){
					return
				}
				
				apiPage(this.searchDate).then((data)=>{
					let list = data.records
					list.forEach(item =>{
						this.dataList.push(item)
					})
				})
			},
			del(index){
				this.dataList.splice(index,1)
			},
			getItemByIndex(index){
				return this.dataList[index]
			}
		}
	}
</script>

<style>
</style>
